﻿using System;
using System.Collections.Specialized;
using System.Web.UI;

namespace MPBlog.UserControls
{
    public abstract partial class WidgetBase : System.Web.UI.UserControl
    {
        #region - property -

        public virtual bool DisplayHeader
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        /// 是否可编辑
        /// </summary>
        public abstract bool IsEditable { get; }

        /// <summary>
        /// widget名字（与所在的文件夹同名，一般为英文名）
        /// </summary>
        public abstract string Name { get; }

        /// <summary>
        /// 是否显示widget标题
        /// </summary>
        public bool ShowTitle { get; set; }

        /// <summary>
        /// widget标题
        /// </summary>
        public abstract string Title { get;}

        /// <summary>
        /// widget GUID,用于唯一确定正在使用的widget
        /// </summary>
        public Guid WidgetId { get; set; }

        /// <summary>
        /// 所属的zone的名字
        /// </summary>
        public string Zone { get; set; }

        #endregion

        /// <summary> 
        /// 这个方法在用户自定义的widget中被重写 
        /// </summary> 
        public abstract void LoadWidget();

        protected override void Render(HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new NullReferenceException("widget必须有一个名字");
            }
            base.Render(writer);
        }
    }
}